package com.kerbores.wzcc.modules;

import java.io.IOException;

import org.nutz.json.Json;
import org.nutz.lang.Lang;
import org.nutz.lang.util.NutMap;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Fail;
import org.nutz.mvc.annotation.IocBy;
import org.nutz.mvc.annotation.Modules;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;
import org.nutz.mvc.ioc.provider.ComboIocProvider;

import com.assic.utils.net.URLPoster;
import com.assic.utils.vo.Result;
import com.kerbores.wzcc.modules.base.BaseModule;

/**
 * @author Ixion
 * 
 *         create at 2014年7月18日
 */
@Modules(scanPackage = true)
@IocBy(type = ComboIocProvider.class, args = { "*org.nutz.ioc.loader.annotation.AnnotationIocLoader", "com.kerbores.wzcc" })
@At("/")
@Fail("json")
public class MainModule extends BaseModule {

	@At("citys")
	@Ok("json")
	public Result main() {
		NutMap map = null;
		try {
			map = Lang.map(URLPoster.simpleUTF8Post("http://apis.haoservice.com/weizhang/citys", "key=8ff45540c1364ad6b1b0d7479bf3d1f8"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		return map == null ? Result.fail("接口失败!") : Result.success().setData(map);
	}

	@At("types")
	@Ok("json")
	public Result types() {
		NutMap map = null;
		try {
			map = Lang.map(URLPoster.simpleUTF8Post("http://apis.haoservice.com/weizhang/hpzl", "key=8ff45540c1364ad6b1b0d7479bf3d1f8"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		return map == null ? Result.fail("接口失败!") : Result.success().setData(map);
	}

	@At("query")
	@Ok("json")
	public Result query(@Param("city") String city, @Param("type") String type, @Param("plate") String plate, @Param("eng") String eng) {
		NutMap map = null;
		NutMap pa = new NutMap();
		pa.put("key", "8ff45540c1364ad6b1b0d7479bf3d1f8");
		pa.put("city", city);
		pa.put("hphm", plate);
		pa.put("hpzl", type);
		pa.put("engineno", eng);
		System.out.println(Json.toJson(pa));
		try {
			map = Lang.map(URLPoster.simpleUTF8Post("http://apis.haoservice.com/weizhang/query", pa));
		} catch (IOException e) {
			e.printStackTrace();
		}
		return map == null ? Result.fail("接口失败!") : Result.success().setData(map);
	}
}
